<template>
  <div>
    <div class="login-parsel">
      <p style="padding-top:1.5rem;">
        <el-icon style="font-size: 1.2rem" @click="router.go(-1)"
          ><Back
        /></el-icon>
      </p>
      <p style="font-size: 1.5rem;padding-top:1.5rem;">创建新密码</p>
      <p style="font-size: 0.9rem; color: gray; line-height: 0.1rem;padding-top:1.5rem;">
        文字描述信息示例
      </p>
      <div style="margin-top: 3.5rem">
        <el-form>
          新密码<br />
          <el-input
            v-model="newpwd"
            style="
              width: 21.8rem;
              height: 2.7rem;
              margin-top: 0.5rem;
              border: 1px solid #d0d0d0;
              border-radius: 0.3rem;
            "
            type="password"
            placeholder="输入您的新密码"
            show-password
          />
          <p style="padding-top:1.5rem;">
            旧密码<br />
            <el-input
              v-model="oldpwd"
              style="
                width: 21.8rem;
                height: 2.7rem;
                margin-top: 0.5rem;
                border: 1px solid #d0d0d0;
                border-radius: 0.3rem;
              "
              type="password"
              placeholder="输入您的旧密码"
              show-password
            />
          </p>
        </el-form>

        <button class="create-btn" @click="createpwd">创建新密码</button>
      </div>
    </div>
    <div class="zhe" v-if="flag" @click="flag = false">
      <div class="white">
        <div class="qing-outer">
          <div class="qing-inner">
            <el-icon><Select /></el-icon>
          </div>
        </div>
        <p style="font-size: 1.3rem;text-align: center;;">密码更改成功！</p>
        <p style="font-size: 0.9rem; color: gray;line-height: 0.1rem;;">
          文字描述信息示例
        </p>
        <button class="login-btn" >现在登录</button>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import { useRouter,useRoute } from "vue-router";
import {ElMessage} from "element-plus";
import { Back, Select } from "@element-plus/icons-vue";
import axios from "axios";
const router = useRouter();
const route =useRoute();

const newpwd = ref("");
const oldpwd = ref("");
const flag = ref(false);

const createpwd = async() => {
  await axios.post("http://127.0.0.1:3000/zjm/updatepwd",{newpwd:newpwd.value,email:route.query.email}).then((res)=>{
    if(res.data.code = 200){
        flag.value = true;
        router.push('/login')
    }else{
        ElMessage.error('旧密码输入错误')
    }
  })
};
</script>

<style lang="scss" scoped>
.login-parsel {
  width: 90vw;
  height: auto;
  margin: 0 auto;
  padding: 12px;
  box-sizing: border-box;
}
.create-btn {
  width: 85vw;
  height: 3rem;
  margin: 0 auto;
  margin-top: 18rem;
  border: none;
  border-radius: 0.5rem;
  background-color: #ffb900;
  color: white;
  font-size: 1.2rem;
}
.login-btn {
  width: 65vw;
  height: 3rem;
  border: none;
  border-radius: 0.5rem;
  background-color: #ffb900;
  color: white;
  font-size: 1.2rem;
  margin-top:1.5rem;
}
.zhe {
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.35);
  position: fixed;
  top: 0;
  left: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  .white {
    width: 80vw;
    height: 43vh;
    background-color: white;
    border-radius: 0.5rem;
    text-align: center;
  }
}
.qing-outer{
    width:6.5rem;
    height: 6.5rem;
    margin: 0 auto;
    margin-top: 1.5rem;
    background:#ddf3ef ;
    border-radius: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}
.qing-inner{
    width:4.3rem;
    height:4rem;
    background:#40c4aa;
    border-radius: 50%;
    border-radius: 1.5rem;
    color:white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;

}
</style>